<template>
  <div class="app-container">
    <div class="head-container">
      <div class="btnContain">
        <el-button @click="addAdver">新建</el-button>
      </div>
    </div>
    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" border :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table-column :show-overflow-tooltip="true" prop="content" label="内容">
        <template slot-scope="scope">
          <div v-html="scope.row.content" />
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="createdAt" label="创建时间" />
      <el-table-column :show-overflow-tooltip="true" prop="expiryDate" label="过期时间" />
      <el-table-column
        label="操作"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="deleItem(scope.row)">撤回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import crudAdvertisement from '@/api/advertisement'
import CRUD, { presenter, header, crud } from '@crud/crud'
import pagination from '@crud/Pagination'
import { mapGetters } from 'vuex'
export default {
  name: 'Advertisement',
  components: { pagination },
  cruds() {
    return CRUD({ title: '广告', url: 'api/advertisement', crudMethod: { ...crudAdvertisement }})
  },
  mixins: [presenter(), header(), crud()],
  // 数据字典
  data() {
    return {
      height: document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    deleItem(row) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await crudAdvertisement.del([row.id])
        this.crud.toQuery()
        this.$message({
          type: 'success',
          message: '已删除!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    addAdver() {
      this.$router.push({
        path: '/help/adver/addAdver'
      })
    }
  }
}
</script>

        <style rel="stylesheet/scss" lang="scss" scoped>
          .head-container {
            display: flex;
            justify-content: space-between;
            .btnContain {
              ::v-deep .el-button {
              background-color: rgba(236, 91, 91, 1);
              color: #fff;
              border: 0;
            }
            }
          }

        </style>

